package lk.icta.core.dao.impl;

import lk.icta.common.dao.impl.BaseDAO;
import lk.icta.core.dao.LeaseDetailsDAO;
import lk.icta.core.entity.LeaseDetail;
import lk.icta.user.entity.User;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Duminda Dharmakeerthi
 */
public class LeaseDetailDAOImpl extends BaseDAO implements LeaseDetailsDAO {

    @Transactional(propagation = Propagation.MANDATORY)
    public void addLeaseDetails(LeaseDetail leaseDetail, User user) {
      //  logger.debug("Adding Lease Details [Lease Diagram No: {}]", leaseDetail.getLeaseDiagramNo());
        em.persist(leaseDetail);
    }

    @Transactional(propagation = Propagation.MANDATORY)
    public void updateLeaseDetails(LeaseDetail leaseDetail, User user) {
       // logger.debug("Updating Lease Details [Lease Diagram No: {}]", leaseDetail.getLeaseDiagramNo());
        em.merge(leaseDetail);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    public LeaseDetail getLeaseDetailById(long id, User user) {
        logger.debug("Loading Lease Detail of id: {}", id);
        return em.find(LeaseDetail.class, id);
    }
}
